import os
import json
import ast
from collections.abc import Callable
# import filetype

_env = os.environ

# 获取环境变量，并通过func进行转换
# 增加 assert 步骤，防止环境变量不存在
def get_env(env_var: str, func: Callable = str):
    _env_var = _env.get(env_var)
    assert _env_var is not None
    result = func(_env_var)
    # print(f"env var ${env_var}: {result}")
    return result


with open("config/client.config.json","r") as fr:
    config = json.load(fr)

Localhost = "127.0.0.1"

ClientWebIP = config["pythonApp"]["web"]["ip"]
ClientWebPort = config["pythonApp"]["web"]["port"]

ClientUIBackendIP = config["pythonApp"]["ui_backend"]["ip"]
ClientUIBackendPort = config["pythonApp"]["ui_backend"]["port"]

EthereumIP = config["ethereum"]["ip"]
EthereumPort = config["ethereum"]["port"]

IPFSIP = config["ipfs"]["ip"]
IPFSPort = config["ipfs"]["port"]

AccountKeyPath = config["accountkeys"]["path"]

TmpFolder = config["temporary"]["tmpfolder"]
TmpKeysFolder = config["temporary"]["tmpkeys"]
TmpABEFolder = config["temporary"]["abe_tmp"]
TmpIPFSFolder = config["temporary"]["ipfs_tmp"]

# DOContractFile = config["solidity"]["DOContract"].split(":")[0]
# DUContractFile = config["solidity"]["DUContract"].split(":")[0]
contractFile = config["solidity"]["contractFile"]
DOContract = config["solidity"]["DOContract"]
DUContract = config["solidity"]["DUContract"]


DBPath = config["database"]["db"]

HighestAuthorityAttr = "__OWNER__"